#/usr/bin/env python

import os, wx

def image(name, newsize=None):
    cwd = os.getcwd()
    if os.path.exists(os.path.join(cwd, name)):
        name = os.path.join(cwd, name)
    elif os.path.exists(os.path.join(cwd, "images", name)):
        name = os.path.join(cwd, "images", name)
    elif os.path.exists(os.path.join(cwd, "../images", name)):
        name = os.path.join(cwd, "../images", name)
    else:
        #create an default image with "image failed to load written across it...
        if newsize == None:
            newsize = (100, 100)
        return wx.EmptyImage(newsize[0], newsize[1])
    
    img = wx.Image(name)
    if newsize != None:
        img.Rescale(newsize[0], newsize[1])
    return img

def bitmap(name, newsize=None):
    return image(name, newsize).ConvertToBitmap()